namespace System.Xml.Serialization
{
    using System;
    using System.IO;

    [Serializable]
    public abstract class XmlFileStreamSerializer<T> : XmlStreamSerializer<T>,
        IXmlTypeSerializer<T, MemoryStream>,
        IXmlFileSerializer<T>
    {
        protected abstract T Deserialize(string fileName, IXmlTypeFormatter formatter);
        protected abstract void Serialize(string fileName, T obj, IXmlTypeFormatter formatter);

        T IXmlFileSerializer<T>.Deserialize(string fileName)
        {
            lock (((XmlFileStreamSerializer<T>)this))
            {
                return this.Deserialize(fileName, XmlTypeFormatter);
            }
        }

        T IXmlFileSerializer<T>.Deserialize(string fileName, IXmlRuntimeFormatter formatter)
        {
            lock (((XmlFileStreamSerializer<T>)this))
            {
                return this.Deserialize(fileName, formatter);
            }
        }

        void IXmlFileSerializer<T>.Serialize(T obj, string fileName)
        {
            lock (((XmlFileStreamSerializer<T>)this))
            {
                this.Serialize(fileName, obj, XmlTypeFormatter);
            }
        }

        void IXmlFileSerializer<T>.Serialize(T obj, string fileName, IXmlRuntimeFormatter formatter)
        {
            lock (((XmlFileStreamSerializer<T>)this))
            {
                this.Serialize(fileName, obj, formatter);
            }
        }
    }
}

